/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#ifndef __REF_H
#define __REF_H

#include "../qcommon/qcommon.h"

#define	MAX_DLIGHTS		32
#define	MAX_STAINS		32
#define	MAX_ENTITIES	128
#define	MAX_PARTICLES	4096
#define	MAX_LIGHTSTYLES	256

#define MAX_RENDER_ENTITIES			2048
#define MAX_RENDER_LIGHTS			64
#define MAX_RENDER_PARTICLES			8192

#define POWERSUIT_SCALE		4.0F

#define SHELL_RED_COLOR		0xF2
#define SHELL_GREEN_COLOR	0xD0
#define SHELL_BLUE_COLOR	0xF3

#define SHELL_RG_COLOR		0xDC
//#define SHELL_RB_COLOR		0x86
#define SHELL_RB_COLOR		0x68
#define SHELL_BG_COLOR		0x78

//ROGUE
#define SHELL_DOUBLE_COLOR	0xDF // 223
#define	SHELL_HALF_DAM_COLOR	0x90
#define SHELL_CYAN_COLOR	0x72
//ROGUE

#define MAX_MATERIAL_PARMS			8

#define SHELL_WHITE_COLOR	0xD7
#if 0
enum reType_t
{
	RE_MODEL,
	RE_SPRITE,
	RE_BEAM
};

struct renderEntity_t
{
	//struct model2_t		*model2;			// opaque type outside refresh
	float				angles[3];
#ifdef GL_QUAKE
	vec3_t				axis[3];
#endif

	reType_t			reType;
	int					renderFX;			// FX flags

	int					index;				// Set by the renderer

	struct model_t		*model;				// Opaque type outside renderer

	// Model animation data
	int					frame;
	int					oldFrame;

	float				backLerp;			// 0.0 = current, 1.0 = old

	/*
	** most recent data
	*/
	float				origin[3];		// also used as RF_BEAM's "from"
	//int					frame;			// also used as RF_BEAM's diameter

	/*
	** previous data for lerping
	*/
	float				oldorigin[3];	// also used as RF_BEAM's "to"
	//int					oldframe;

	/*
	** misc
	*/
	//float	backlerp;				// 0.0 = current, 1.0 = old
	//int		skinnum;				// also used as RF_BEAM's palette index

	int		lightstyle;				// for flashing entities
	float	alpha;					// ignore if RF_TRANSLUCENT isn't set

	struct image_t	*skin;			// NULL for inline skin
	int		flags;

	int					skinIndex;			// Model texturing

	float				depthHack;			// Depth range hack to avoid poking into geometry

	// Material information
	struct material_t	*customMaterial;	// Can be NULL for models

	float				materialParms[MAX_MATERIAL_PARMS];
};

struct renderLight_t {
	// Transformation matrix
	vec3_t				origin;
	vec3_t				center;				// Relative to origin
	vec3_t				axis[3];
	vec3_t				radius;

	// Light settings
	int					style;
	int					detailLevel;
	qboolean			parallel;			// Light center gives the direction to the light at infinity
	qboolean			noShadows;

	// Material information
	struct material_t	*customMaterial;	// If NULL, _defaultLight will be used

	float				materialParms[MAX_MATERIAL_PARMS];
};

struct renderPolyVertex_t
{
	vec3_t				xyz;
	vec3_t				normal;
	vec2_t				st;
	color_t				color;
};

struct renderPoly_t
{
	struct material_t	*material;

	// Geometry in triangle-fan order
	int					numVertices;
	renderPolyVertex_t	*vertices;
};
#endif
#define ENTITY_FLAGS  68

struct dlight2_t
{
	vec3_t	origin;
	vec3_t	color;
	float	intensity;
};

struct particle2_t
{
	vec3_t	origin;
	int		color;
	float	alpha;
};

struct lightstyle_t
{
	float		rgb[3];			// 0.0 - 2.0
	float		white;			// highest of rgb
};

struct stain_t
{
	vec3_t			origin;
	float			size;
	float			color[3];
};
#if 0
struct renderView_t
{
	// Viewport definition
	int					x;
	int					y;
	int					width;
	int					height;

	float				fovX;
	float				fovY;

	// Transformation matrix
	vec3_t				viewOrigin;
	vec3_t				viewAxis[3];

	// Material parms
	float				materialParms[MAX_MATERIAL_PARMS];

	// -----

	float				viewangles[3];

	float		blend[4];			// rgba 0-1 full screen blend
	float		time;				// time is uesed to auto animate
	int			rdflags;			// RDF_UNDERWATER, etc

	byte		*areaBits;			// if not NULL, only areas with set bits will be drawn

	lightstyle_t	*lightstyles;	// [MAX_LIGHTSTYLES]

	int			num_entities;
	renderEntity_t	*entities;

	int			num_dlights;
	dlight2_t	*dlights;

	int			num_particles;
	particle2_t	*particles;
};

struct glConfig_t
{
	const char			*vendorString;
	const char			*rendererString;
	const char			*versionString;
	const char			*extensionsString;

#ifdef WIN32
	const char			*wglExtensionsString;
#endif

	int					colorBits;
	int					alphaBits;
	int					depthBits;
	int					stencilBits;
	int					samples;

	bool				deviceSupportsGamma;
	bool				isFullscreen;
	int					displayFrequency;
	int					videoWidth;
	int					videoHeight;

	bool				multitexture;
	bool			    textureCubeMap;
	bool				textureNonPowerOfTwo;
	bool                textureCompression;
	bool                textureBorderClamp;
	bool                multisample;
	bool				vertexBufferObject;
	bool				GLSL;
	bool				vertexShader;
	bool				fragmentShader;
	bool				shaderObjects;
	bool				drawRangeElements;
	bool				textureFilterAnisotropic;
	bool				textureLODBias;
	bool				stencilWrap;
	bool				stencilTwoSide;
	bool				atiSeparateStencil;
	bool				depthBoundsTest;
	bool				swapControl;

	int					maxVertexUniforms;
	int					maxVaryingFloats;
	int					maxVertexAttribs;
	int					maxFragmentUniforms;
	int					maxCubeMapTextureSize;
	float				maxTextureMaxAnisotropy;
	float				maxTextureLODBias;

	int         renderer;
	const char *renderer_string;
	const char *vendor_string;
	const char *version_string;
	const char *extensions_string;

	qboolean	allow_cds;

	int			maxTextureSize;
	int			maxTextureUnits;

	qboolean	anisotropic;
	int			maxAnisotropic;
};

extern glConfig_t  glConfig;
#endif
/* REFIMPORT */

//void VID_MenuInit( void );
void VID_NewWindow ( int width, int height);

/* REFEXPORT */
void	R_BeginRegistration (const char *map);

struct model2_t	*R_RegisterModel2 (const char *name);
struct image_t	*R_RegisterSkin (const char *name);
struct image_t	*Draw_FindPic (const char *name);

//void    R_RenderFrame (renderView_t *fd);

void	R_SetSky (const char *name, float rotate, vec3_t axis);
void	R_EndRegistration (void);

void	Draw_GetPicSize (int *w, int *h, const char *name);
void	Draw_Pic (int x, int y, const char *name, float alpha);
void	Draw_StretchPic (int x, int y, int w, int h, const char *name, float alpha);
void	Draw_ScaledPic (int x, int y, float scale, const char *name, float red, float green, float blue, float alpha);
void	Draw_Char (int x, int y, int c, int color, float alpha);
void	Draw_TileClear (int x, int y, int w, int h, const char *name);
void	Draw_Fill (int x, int y, int w, int h, int c);
void	Draw_FadeScreen (void);
void	Draw_StretchRaw (int x, int y, int w, int h, int cols, int rows, byte *data);

int 	R_InitOld();
void	R_ShutdownOld( void );

void	R_CinematicSetPalette ( const unsigned char *palette);
void	R_BeginFrameOld( float camera_separation );

void	R_EndFrameOld( void );
void	R_AppActivate( qboolean active );

#ifdef GL_QUAKE
void R_AddDecal	(vec3_t origin, vec3_t dir, float red, float green, float blue, float alpha,
				 float size, int type, int flags, float angle);


void R_AddStain (const vec3_t org, int color, float size); //Stainmaps
#else
#define R_AddStain(a,b,c)
#endif

#endif // __REF_H
